<template>
  <div>
    <el-dialog
      v-model="props.isShow"
      :title="props.isAdd ? '添加' : '编辑'"
      center
      :before-close="cancel"
    >
      <el-form :model="cateForm" ref="diaRef" :rules="rules">
        <!-- <el-form-item label="Promotion name" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off" />
        </el-form-item> -->
        <el-form-item label="Zones" :label-width="formLabelWidth">
          <el-select placeholder="请选择上级分类" v-model="cateForm.pid">
            <el-option label="顶级分类" :value="0" />
            <el-option
              v-for="item in store.getters['cate/getCate']"
              :key="item.id"
              :label="item.catename"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancel(diaRef)">取消</el-button>
          <el-button type="primary" @click="confirm(diaRef)"> 确定 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, defineProps, defineEmits } from "vue";
import type { FormInstance, FormRules, UploadFile } from "element-plus";
import {useStore} from 'vuex'
let store = useStore()

let props = defineProps({
  isShow: Boolean,
  isAdd: Boolean,
});
let emit = defineEmits(["cancel"]);
let disRef = ref<FormInstance>();
const formLabelWidth = "140px";

// 双向数据绑定的数据
const cateForm = ref({
  pid: "", //       上级分类编号
  catename: "", //  商品分类名称
  img: "", //       图片(文件，一般用于二级分类)
  status: 1, //    状态            1正常2禁用
});

let rules = reactive<FormRules>({
  catename: [
    { required: true, message: "请输入分类名称", trigger: "blur" },
    { min: 2, max: 6, message: "Length should be 2 to 6", trigger: "blur" },
  ],
  pid: [
    {
      required: true,
      message: "请选择上级菜单",
      trigger: "change",
    },
  ],
});

// 取消
const cancel = () => {
  emit("cancel");
};
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
